package io.persimmon.core.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class EntityChange<O, N> {
    private O oldEntity;
    private N newEntity;

    public List<?> getAllData() {
        List<Object> list = new ArrayList<>();
        if (Objects.nonNull(oldEntity)) {
            if (oldEntity instanceof Collection) {
                list.addAll((Collection<?>) oldEntity);
            } else {
                list.add(oldEntity);
            }
        }
        if (Objects.nonNull(newEntity)) {
            if (newEntity instanceof Collection) {
                list.addAll((Collection<?>) newEntity);
            } else {
                list.add(newEntity);
            }
        }
        return list;
    }
}
